package demo;

import helloword.MyService;
import org.apache.thrift.TException;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TFramedTransport;
import org.apache.thrift.transport.TNonblockingSocket;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;

import java.io.IOException;

public class TestClient {

    public static void main(String[] args) throws TException, IOException {
        //创建socket
        TTransport transport = new TFramedTransport(new TSocket("localhost", 8080));
//        TTransport transport = new TSocket("localhost", 8080);
        //链接远程服务器
        transport.open();

        //创建传输数据的类型 是binary json 等 协议里面包含了 transport 因为写协议要使用底层的stream API
        TProtocol protocol = new TBinaryProtocol(transport);
        MyService.Client client = new MyService.Client(protocol);

        System.out.println(client.say("HelloWorld", 10));
//        System.out.println(client.say("HelloWorld", 11));
        transport.close();
    }
}
